package com.company.mediator.sample01;
import java.util.*;

// Concrete Mediator
public class ChatGroup extends AbstractChatroom
{
	private Hashtable members=new Hashtable();

	//注册同事的机�?
	public void register(Member member)
	{
		if(!members.contains(member))
		{
			members.put(member.getName(),member);
			member.setChatroom(this);  //在注册的同时，告诉同事类中介者相关信�?
		}
	}
	
   public void sendText(String from,String to,String message)
   {
   	  Member member = (Member)members.get(to);
   	  String newMessage = message;
   	  newMessage = message.replaceAll("AA","*");
	  member.receiveText(from,newMessage);
   }
   
   public void sendImage(String from,String to,String image)
   {
   	  Member member=(Member)members.get(to);
   	  //中介者在传递消息的同时，可对同事的消息进一步处理
   	  if(image.length()>5)
   	  {
   	  	  System.out.println("cannot show image");
   	  }
   	  else
   	  {
   	  	  member.receiveImage(from,image);
   	  }
   }
}